<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$id=intval($_RQ['id']);

	$return['account']=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('token','aeskey'));
	$return['account']['url']=$_AR['siteroot'].'api/wxapi.php?id='.$_SESSION['uniacid'];
	$return['item']['url']=$return['account']['url'];
	$return['item']['token']=$return['account']['token'];
	$return['item']['aeskey']=$return['account']['aeskey'];
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			
		),
		'edits'=>array(
			'0'=>array(
				'title'=>'上传证书',
				'list'=>array(
				
					array('type'=>'upfile','title'=>'cert证书','name'=>'cert','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_cert.pem，并在此处上传。'),
					array('type'=>'upfile','title'=>'key证书','name'=>'key','help'=>'从商户平台上下载支付证书, 解压并取得其中的 apiclient_key.pem，并在此处上传。'),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='post'){
	//exi('dd','error');
	//提交数据
	$post=get_postdata();
	//以公众号uniacid生成文件夹
	$dir = iconv("UTF-8", "GBK", ROOT_D.'/addons/jy_h5game/cert/'.$_SESSION['uniacid']);
        if (!file_exists($dir)){
            mkdir ($dir,0777,true);
          //  echo '创建文件夹成功';
        } else {
          //  echo '需创建的文件夹已经存在';
        }
	$id=intval($post['id']);
	$data=array();
	//上传cert证书
		if($post['cert']&&$post['key']){
		
		$certfilename=pdo_getcolumn('core_attachment',array('attachment'=>$post['cert']),'title');
		$keyfilename=pdo_getcolumn('core_attachment',array('attachment'=>$post['key']),'title');
		
		$certfile_data=cfc('files')->source_read($post['cert']);
		$keyfile_data=cfc('files')->source_read($post['key']);
		
		file_put_contents(ROOT_D.'/addons/jy_h5game/cert/'.$_SESSION['uniacid'].'/'.$certfilename.'.pem',$certfile_data);
		file_put_contents(ROOT_D.'/addons/jy_h5game/cert/'.$_SESSION['uniacid'].'/'.$keyfilename.'.pem',$keyfile_data);
		
		exi('认证文件上传成功','error');
	}
	else{
		
		exi('cert证书和key证书必须都上传','error');
	}

}

